package com.sxm.yiwei.adapters;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.sxm.yiwei.R;
import com.sxm.yiwei.beans.FWBook;
import com.sxm.yiwei.utils.InternetAddressUtis;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.HashMap;
import java.util.List;

/**
 * Created by KuKa on 2017/7/13.
 * 服务 出售中
 */

public class SellServiceListAdapter extends BaseAdapter {
    Context context;
   public List<FWBook.DataBean> list;
    OnClickListenerEditOrDelete onClickListenerEditOrDelete;
    public SellServiceListAdapter(Context context,  List<FWBook.DataBean> list) {
        this.context=context;
        this.list=list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View view;
        ViewHolder holder;
        if (convertView==null){
            view = View.inflate(context, R.layout.sellservicelist_item,null);
            holder = new ViewHolder();
            holder.selldelete = (TextView) view.findViewById(R.id.adsellservice_delete);
            holder.selledit = (TextView) view.findViewById(R.id.adsellservice_edit);
            holder.sellview = (TextView) view.findViewById(R.id.adsellservice_setview);
            holder.contenttext = (TextView) view.findViewById(R.id.adsellservice_contenttext);
            holder.explain = (TextView) view.findViewById(R.id.adsellservice_listcontent);
            holder.grade = (ImageView) view.findViewById(R.id.adsellservice_pinglun1);
            holder.img = (ImageView) view.findViewById(R.id.adsellservice_listimg);
            holder.name = (TextView) view.findViewById(R.id.adsellservice_listname);
            holder.people = (TextView) view.findViewById(R.id.adsellservice_listpeoplenumber);
            view.setTag(holder);
        }else {
            view = convertView;
            holder = (ViewHolder) view.getTag();
        }
        holder.name.setText(list.get(position).getName());
        holder.people.setText(list.get(position).getVolume()+" 人付款");
        holder.explain.setText(list.get(position).getAmount()+"");
        holder.contenttext.setText(list.get(position).getIntro());
        Picasso.with(context).load(InternetAddressUtis.IMG_URL+list.get(position).getServiceAvatar()).error(R.mipmap.morentouxiang).into(holder.img);

        holder.sellview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickListenerEditOrDelete!=null){
                    onClickListenerEditOrDelete.OnClickListenersetView(position);
                }
            }
        });

        holder.selldelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickListenerEditOrDelete!=null){
                    onClickListenerEditOrDelete.OnClickListenerDelete(position);
                }
            }
        });
        holder.selledit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickListenerEditOrDelete!=null){
                    onClickListenerEditOrDelete.OnClickListenerEdit(position);
                }
            }
        });
        return view;
    }

    class ViewHolder{
        TextView selldelete,selledit,sellview;
        ImageView img,grade;
        TextView name,contenttext,explain,people;

    }

    public interface OnClickListenerEditOrDelete{
        void OnClickListenerEdit(int position);
        void OnClickListenerDelete(int position);
        void OnClickListenersetView(int position);

    }

    public void setOnClickListenerEditOrDelete(OnClickListenerEditOrDelete onClickListenerEditOrDelete1){
        this.onClickListenerEditOrDelete=onClickListenerEditOrDelete1;
    }
}
